package tor;

import java.io.IOException;
import java.io.OutputStream;

import org.silvertunnel.netlib.api.NetFactory;
import org.silvertunnel.netlib.api.NetLayer;
import org.silvertunnel.netlib.api.NetLayerIDs;
import org.silvertunnel.netlib.api.NetSocket;
import org.silvertunnel.netlib.api.util.TcpipNetAddress;
public class TorClient
{
	public static void main(String [] args) throws IOException{
		String remoteHostname = "127.0.0.1";
	    int remotePort = 59665;
	    TcpipNetAddress remoteAddress = new TcpipNetAddress(remoteHostname, remotePort);
	 // get TorNetLayer instance and wait until it is ready
	    NetLayer netLayer = NetFactory.getInstance().getNetLayerById(NetLayerIDs.TOR);
	    netLayer.waitUntilReady();
	 // open connection to remote address - this connection is tunneled through the TOR anonymity network
	    NetSocket netSocket = netLayer.createNetSocket(null, null, remoteAddress);
	 // send and receive data
	    // hint: to avoid dead locks: use separate threads for each direction
	    OutputStream os = netSocket.getOutputStream();
	    String asd = "OLABOGA!";
	    byte[] aaa = asd.getBytes();
	    os.write(aaa);
	    // ... 
	 // close connection
	    // hint: this should be done in a finally block
	    netSocket.close();
	}

}